﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace msBsc.WebUi.wMall.Public
{
    public partial class wfForgotPassword1 : msBsc.Cls.BPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        private void userCode()
        {
            string code = this.GetParamHtValue("Code");
            string account = this.GetParamHtValue("userName");
            if (code != (string)GetSession(this.sCurrPageRadom + msBsc.Cls.ValidateCode.VALIDATECODEKEY, "2"))
            {
                this.ExecJScript(@"jQuery.getValidateImg('imgValidata');alert(""验证码错误或已过期，请重新录入！"")");
                return;
            }
            if (string.IsNullOrEmpty(account))
            {
                this.Alert("帐号不能为空");
                return;
            }
            using (msBsc.AppLogic.DataAlc.CBizCustomerBaseInfo baseInfo = new AppLogic.DataAlc.CBizCustomerBaseInfo())
            {
                DataSet ds = baseInfo.SelectUserEmail(account);
                if (ds == null || ds.Tables[0].Rows.Count != 1)
                {
                    this.Alert("该帐号没有注册，请去注册");
                }
                else
                {
                    this.ExecJScript(@"firstNext(0);$(""#J_useremail_input"").val('" + ds.Tables[0].Rows[0]["CUSTOMER_BASEINFO_EMAIL"] + "');");
                }
            }

        }

        private void sendEmailCode()
        {
            string account = this.GetParamHtValue("account");
            if (string.IsNullOrEmpty(account))
            {
                this.Alert("请选择你要修改的帐号");
                return;
            }
            string email = this.GetParamHtValue("email");
            if (string.IsNullOrEmpty(email))
            {
                this.Alert("您没有填邮箱，暂时不支持非邮箱修改");
                return;
            }
            string strurl = msBsc.AppLogic.Cfg.DesCry.encMe(account + "," + DateTime.Now.AddMinutes(30).ToString("yyyy-MM-dd HH:mm:ss"), "rmdes");
            string url = msBsc.AppLogic.Cfg.SystemFileDir.FileDir.httpUrl + "wp_ChangePassword.htm?KEY=" + strurl;
            string content = @"<div style='width:600px;font-size:14px; font-family:微软雅黑;padding-left:5px;text-decoration:none;'><div>您好:</div><div style='padding-left:30px;'><div>感谢您使用地接客旅游网!</div><div>您正在进行找回密码操作，请点击一下连接完成重置密码：<a  target='_blank' href='{0}'>{1}</a></div><div style='margin-left:400px;'>地接客旅游网</div><div style='margin-left:400px;'>{2}</div></div></div>";
            msBsc.SvRef.SendEMail sendEmail = new msBsc.SvRef.SendEMail();
            sendEmail.SendEmailTo(email, email, "地接客找回密码", string.Format(content, url, url, DateTime.Now));
            this.SetContrlValue("J_btn_phone_code", "重新获找回密码路径");
            this.Alert("请去您的邮箱继续完成找回密码功能");
        }

       

        public override void DoAction()
        {
            if (this.strAction == "userCode")
            {
                userCode();
            }
            else if (this.strAction == "sendEmail")
            {
                sendEmailCode();
            }
           
        }
    }
}